package com.how.warlock.engine;

import static org.lwjgl.opengl.GL11.*;

import org.lwjgl.opengl.GL11;

public class AnimatedSprite extends Sprite {
	private Texture[] textures;
	
	private int width, height;
	
	public AnimatedSprite(Texture[] textures) {
		super();
		this.textures = textures;
		this.width = textures[0].getImageWidth();
		this.height = textures[0].getImageHeight();
	}
	
	public int getFrames(){
		return textures.length;
	}
	
	public int getWidth(){
		return width;
	}
	
	public int getHeight(){
		return height;
	}
	
	public void draw(int x, int y, int frame){
		Texture texture = textures[frame]; 
		
		glPushMatrix();
		glEnable(GL_TEXTURE_2D);
		
		texture.bind();
		
		GL11.glColor3f(1f, 1f, 1f);
		
		glTranslatef(x,y,0);

		glBegin(GL_QUADS);{
			glTexCoord2f(0, 0);
			glVertex2f(0, 0);
			
			glTexCoord2f(0, texture.getHeight());
		
			glVertex2f(0, height);
			
			glTexCoord2f(texture.getWidth(), texture.getHeight());
			glVertex2f(width, height);
			
			glTexCoord2f(texture.getWidth(), 0);
			glVertex2f(width, 0);
		}
		
		glEnd();
		
		glPopMatrix();
	}
	
	public void draw(int x, int y, int frame, float scale){
		Texture texture = textures[frame]; 
		
		glPushMatrix();
		glEnable(GL_TEXTURE_2D);
		
		texture.bind();
		
		GL11.glColor3f(1f, 1f, 1f);
		
		glTranslatef(x,y,0);

		glBegin(GL_QUADS);{
			glTexCoord2f(0, 0);
			glVertex2f(0, 0);
			
			glTexCoord2f(0, texture.getHeight());
		
			glVertex2f(0, height * scale);
			
			glTexCoord2f(texture.getWidth(), texture.getHeight());
			glVertex2f(width * scale, height * scale);
			
			glTexCoord2f(texture.getWidth(), 0);
			glVertex2f(width * scale, 0);
		}
		
		glEnd();
		
		glPopMatrix();
	}
}
